<?php

namespace App\Admin\Controllers;

use App\Models\Type;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;

class TypesController extends AdminController
{
    public function index(Content $content): Content
    {
        return $content
            ->header('列表')
            ->description('全部')
            ->breadcrumb(['text' => '列表', 'url' => ''])
            ->body($this->grid());
    }

    protected function grid()
    {
        return Grid::make(new Type(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name')->label('pink');
            $grid->column('created_at');
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->like('name');
            });
        });
    }

    protected function form(): Form
    {
        return Form::make(new Type(), function (Form $form) {
            $form->display('id');
            $form->text('name')->required();

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
